package com.ruoyi.web.controller.wq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqQuestion;
import com.ruoyi.wq.domain.vo.WqQuestionVO;
import com.ruoyi.wq.service.IWqQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.QuestionService;

/**
 * 用户提问Controller
 * 
 * @author ruoyi
 * @date 2024-04-04
 */
@RestController
@RequestMapping("/wq/question")
public class WqQuestionController extends BaseController {

    @Autowired
    private IWqQuestionService wqQuestionService;
    
    @Autowired
    private QuestionService questionService;
    
    /**
     * 查询问题列表
     */
    @Anonymous
    @GetMapping("/list")
    public AjaxResult list(WqQuestionVO wqQuestion){
    	return questionService.getPageList(wqQuestion);
    }
    
    /**
     * 查询问题列表
     */
    @GetMapping("/myList")
    public AjaxResult myList(WqQuestionVO wqQuestion){
    	return questionService.getMyPageList(wqQuestion);
    }
    
    /**
     * 新增提问
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WqQuestion wqQuestion){
        return AjaxResult.success(questionService.add(wqQuestion));
    }
    
    /**
     * 删除用户提问
     */
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody WqQuestion wqQuestion) {
        return AjaxResult.success(questionService.remove(wqQuestion.getId()));
    }
    
    /**
     * 解密用户
     */
    @PostMapping("/openUser")
    public AjaxResult openUser(@RequestBody WqQuestion wqQuestion) {
    	questionService.openUser(wqQuestion.getId());
        return AjaxResult.success();
    }
    
    /**
     * 解密所有用户
     */
    @PostMapping("/openAllUser")
    public AjaxResult openAllUser() {
    	questionService.openAllUser();
        return AjaxResult.success();
    }

    /**
     * 导出用户提问列表
     */
    @PreAuthorize("@ss.hasPermi('wq:question:export')")
    @Log(title = "用户提问", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WqQuestion wqQuestion)
    {
        List<WqQuestion> list = wqQuestionService.selectWqQuestionList(wqQuestion);
        ExcelUtil<WqQuestion> util = new ExcelUtil<WqQuestion>(WqQuestion.class);
        util.exportExcel(response, list, "用户提问数据");
    }

    /**
     * 获取用户提问详细信息
     */
    @PreAuthorize("@ss.hasPermi('wq:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wqQuestionService.selectWqQuestionById(id));
    }

    /**
     * 修改用户提问
     */
    @PreAuthorize("@ss.hasPermi('wq:question:edit')")
    @Log(title = "用户提问", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WqQuestion wqQuestion)
    {
        return toAjax(wqQuestionService.updateWqQuestion(wqQuestion));
    }
    
}
